<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表</title>
<link rel="stylesheet"
	href="${ pageContext.request.contextPath }/css/goodslist.css" />
<!-- 引入Jquery -->
<script type="text/javascript"
	src="${ pageContext.request.contextPath }/static/js/jquery-2.1.1.min.js"></script>
<%-- <script type="text/javascript"
	src="${ pageContext.request.contextPath }/js/goodslist.js"></script>
	<script type="text/javascript"
	src="${ pageContext.request.contextPath }/js/goodstype.js"></script> --%>

<link href="${pageContext.request.contextPath}/css/Style1.css"
	rel="stylesheet" type="text/css" />

<!-- 引入样式 -->
<link
	href="${ pageContext.request.contextPath }/static/bootstrap-3.3.7-dist/css/bootstrap.min.css"
	rel="stylesheet">
<script
	src="'${ pageContext.request.contextPath }/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

<script type="text/javascript">
var basepath= '${APP_PATH}';

function refresh(){
	window.location.href = "${pageContext.request.contextPath}/admin/adminProduct_findAllByPage.action?page=1";
}

function addProduct(){
	window.location.href = "${pageContext.request.contextPath}/admin/adminProduct_addPage.action";
}
function edit(pid) {
			window.location.href = "${pageContext.request.contextPath}/admin/adminProduct_edit.action?pid="+pid;
}
function deletecs(pid) {
	var r=confirm("确定删除吗？");
	if (r==true){
		window.location.href = "${pageContext.request.contextPath}/admin/adminProduct_deletecs.action?pid="+pid;
	}
	else{
	}
}
function look(pid) {
	window.location.href = "${pageContext.request.contextPath}/admin/adminProduct_look.action?pid="+pid;
}
function xiajia(pid) {
	var r=confirm("确定要下架该商品吗？");
	if (r==true){
		window.location.href = "${pageContext.request.contextPath}/admin/adminProduct_xiajia.action?pid="+pid;
		alert("商品下架完成");
	}
	else{
		alert("取消商品下架");
	}
}

function shangjia(pid) {
	var r=confirm("确定要上架该商品吗？");
	if (r==true){
		window.location.href = "${pageContext.request.contextPath}/admin/adminProduct_xiajia.action?pid="+pid;
		alert("商品上架完成");
	}
	else{
		alert("取消商品上架");
	}
}

function validate() {
	var condition = document.getElementById("condition").value;
	if (condition == null || condition == '') {
		alert("请输入关键字");
		return false;
	}
	return true;
}

/* $(document).ready(function getcategory_name() {
	$.ajax({
		type : "post",
		dataType : "json",
		url : "${pageContext.request.contextPath}/admin/adminCategorySecond.action",
		data : {},
		success : function(data) {
			var itemtotal = "";
			$.each(data, function(i, item) {
				var cname = item.cname;
				item1 = "<option value='" + cname + "'>" + cname + "</option>";
				itemtotal = itemtotal + item1;
			});
			$("#csid").append(itemtotal);
		},
		error : function(e) {
		}
	});
});  */

</script>

</head>
<body>
	<div class="a">
		<div class="b">
			<form method="post"
				action="${pageContext.request.contextPath}/adminsearchProduct.action">
				<input id="condition" name="condition" type="text" class="input1"
					value="请输入关键词" onfocus="this.value = '';"
					onblur="if (this.value == '') {this.value = '请输入关键词';}">&nbsp;&nbsp;
				<!-- <input id="searchSub" type="submit" value="搜索"
					class="btn btn-primary"> -->
				<button type="submit"
					class="btn btn-primary btn-sm glyphicon glyphicon-search"
					onclick="validate()"></button>
			</form>
		</div>

		<div style="float: left; padding-left: 20px;">
			<form
				action="${pageContext.request.contextPath}/admin/findproByCs.action?csid=${c.csid}">
				<!-- 商品种类： -->
				<select name="csid" id="csid"
					style="height: 32px; width: 120px; border-radius: 4px;">
					<c:forEach var="c" items="${categoryList}">
						<option value="${c.csid }">${c.csname}</option>
					</c:forEach>
				</select> &nbsp;
				<button type="submit"
					class="btn btn-primary btn-sm glyphicon glyphicon-search"></button>
			</form>
		</div>

		<div align="right" style="padding-right: 30px;">
			<input type="button" value="+添加商品" class="btn btn-primary"
				onclick="addProduct()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<button type="button" onclick="refresh()"
				class="btn glyphicon glyphicon-refresh"></button>
		</div>
	</div>

	<div class="d" style="width: 96%; margin-left: 25px;">
		<!-- 显示结果 -->
		<form style="margin-top: 3px;">
			<table width="100%" align="center"
				class="table table-hover table-striped" id="table"
				style="border: 1px solid #D0D0D0">
				<thead>
					<tr align="center" bgcolor="#93b6bd" height="33px;">
						<th scope="col" style="text-align: center;">商品ID</th>
						<th scope="col" style="text-align: center;">商品图片</th>
						<th scope="col" style="text-align: center;">商品名称</th>
						<th scope="col" style="text-align: center;">商品价格</th>
						<th scope="col" style="text-align: center;">是否热门</th>
						<th scope="col" style="text-align: center;">状态</th>
						<th scope="col" style="text-align: center;">操作</th>
					</tr>
				</thead>
				<!-- <tbody></tbody> -->
				<c:forEach items="${allProPageBean.list }" var="p"
					varStatus="status">
					<tr height="30">
						<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="12%">${p.pid}</td>
						<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="16%"><img
							width="40" height="45"
							src="${ pageContext.request.contextPath }/${p.image}"></td>
						<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="17%">${p.pname }</td>
						<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="17%">${p.shopPrice}</td>
						<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="8%"><c:choose>
								<c:when test="${p.isHot==1 }">
														是
										</c:when>
								<c:otherwise>
														否
										</c:otherwise>
							</c:choose></td>

						<td style="CURSOR: hand; HEIGHT: 22px" align="center" width=" "><c:choose>
								<c:when test="${p.state==0}">
														上架中  
														<%-- <button type="button" class="btn btn-warning btn-sm"
										onclick="xiajia(${p.pid})">下架</button> --%>
									<button type="button"
										class="btn btn-warning btn-sm glyphicon glyphicon-arrow-down xia"
										onclick="xiajia(${p.pid})"></button>
								</c:when>
								<c:otherwise>
									<h9 style="color: red;">已下架</h9>
									<%-- <button type="button" class="btn btn-warning btn-sm" 
										onclick="shangjia(${p.pid})">上架</button> --%>
									<button type="button"
										class="btn btn-warning btn-sm glyphicon glyphicon-arrow-up shang"
										onclick="shangjia(${p.pid})"></button>
								</c:otherwise>
							</c:choose></td>
						<%-- <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="9%">
							<c:if test="${p.state==0}">上架中</c:if> <c:if test="${p.state==1}">已下架</c:if>
						</td> --%>
						<td>
							<button type="button"
								class="btn btn-primary btn-sm glyphicon glyphicon-pencil"
								onclick="edit(${p.pid})"></button>&nbsp;
							<button type="button"
								class="btn btn-success btn-sm glyphicon glyphicon-asterisk"
								onclick="look(${p.pid})"></button>
						</td>
					</tr>
				</c:forEach>
			</table>
		</form>
	</div>


	<!-- 分页 -->
	<div align="right"
		style="padding-right: 40px; margin-bottom: 10px; font-size: 13px;">
		第${allProPageBean.page }/${allProPageBean.totlePage}页
		<c:if test="${allProPageBean.page!= 1}">
			<a style="font-size: 13px;"
				href="${pageContext.request.contextPath }/admin/adminProduct_findAllByPage.action?page=1">首页</a>|
			     	<a style="font-size: 13px;"
				href="${pageContext.request.contextPath }/admin/adminProduct_findAllByPage.action?page=${allProPageBean.page-1}">上一页</a>
		</c:if>

		<c:choose>
			<c:when test="${allProPageBean.totlePage<=6}">
				<c:set var="begin" value="1" />
				<c:set var="end" value="${allProPageBean.totlePage}" />
			</c:when>
			<c:otherwise>
				<c:set var="begin" value="${allProPageBean.page-3}" />
				<c:set var="end" value="${allProPageBean.page+3}" />
				<!-- 头溢出 -->
				<c:if test="${begin<1}">
					<c:set var="begin" value="1" />
					<c:set var="end" value="7" />
				</c:if>
				<!-- 尾溢出 -->
				<c:if test="${end>allProPageBean.totlePage}">
					<c:set var="begin" value="${allProPageBean.totlePage-6}" />
					<c:set var="end" value="${allProPageBean.totlePage}" />
				</c:if>
			</c:otherwise>
		</c:choose>
		<%-- <c:forEach begin="1" end="${allProPageBean.totlePage}" var="i"> --%>
		<c:forEach var="i" begin="${begin}" end="${end}">
			<c:choose>
				<c:when test="${allProPageBean.page!=i}">
					<a style="font-size: 13px;"
						href="${ pageContext.request.contextPath }/admin/adminProduct_findAllByPage.action?page=${i}">${i}</a>
				</c:when>
				<c:otherwise>
					<span class="currentPage">${i}</span>
				</c:otherwise>
			</c:choose>
		</c:forEach>

		<c:if test="${allProPageBean.page!= allProPageBean.totlePage }">
			<a style="font-size: 13px;"
				href="${pageContext.request.contextPath }/admin/adminProduct_findAllByPage.action?page=${allProPageBean.page+1}">下一页</a> |
							<a style="font-size: 13px;"
				href="${pageContext.request.contextPath }/admin/adminProduct_findAllByPage.action?page=${allProPageBean.totlePage }">尾页</a>
		</c:if>
	</div>

</body>
</html>

